from django.core.management.base import BaseCommand
from deepseek_api.models import User


class Command(BaseCommand):
    help = '创建管理员账号'

    def handle(self, *args, **options):
        # 检查管理员账号是否已存在
        if User.objects.filter(username='admin').exists():
            self.stdout.write(
                self.style.WARNING('管理员账号已存在')
            )
            return

        # 创建管理员账号
        admin_user = User(
            username='admin',
            email='admin@example.com',
            is_active=True
        )
        admin_user.set_password('admin123')
        admin_user.save()

        self.stdout.write(
            self.style.SUCCESS('管理员账号创建成功！')
        )
        self.stdout.write('用户名: admin')
        self.stdout.write('密码: admin123')
        self.stdout.write('邮箱: admin@example.com')
